import { CommandDialog } from '@amcax/base';
import i18n from '@app-cad/common/utils/i18next';
import { CurvedBaseCommand, CurvedCmdDialogParams } from '@app-cad/types';
import { Polyline } from './polyline';
import { useEffect, useState } from 'react';
const CommandLine = ({ title, onClose, props }: CurvedCmdDialogParams) => {
  // props需要为state，以确保props和mode同时更新，分发的模式不会收到错误的props
  const [editProps, setEditProps] = useState<any>();
  const [editDxid, setEditDxid] = useState<string>();

  useEffect(() => {
    setEditProps(props);
    setEditDxid(props?.shape);
  }, [props?.shape]);

  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'
    >
      <Polyline
        props={editProps}
        onClose={onClose}
        editDxid={editDxid}
      />
    </CommandDialog>
  );
};
export const cmdPolyline: CurvedBaseCommand = {
  id: 'CmdPolyline',
  label: 'command.polyline',
  icon: 'commands/curved/polyline',
  create: (label, onClose, props) => (
    <CommandLine
      title={i18n.t(label)}
      onClose={onClose}
      props={props}
    />
  ),
};
